import * as types from "./mutation-types";
import Api from "api/api";

const state = {
  giftOrderList: {},
  currentGiftOrder: {},
  searchGiftOrderCondition: {
    pageSize: 10,
    orderNo: "",
    verifyCode: "",
    giftTitle: "",
    status: "",
    userName: "",
    userMobile: ""
  }
};

const getters = {
  giftOrderList: state => state.giftOrderList,
  currentGiftOrder: state => state.currentGiftOrder,
  searchGiftOrderCondition: state => state.searchGiftOrderCondition
};

const actions = {
  getGiftOrderPageS({ commit }, param) {
    return Api.getGiftOrderPage(param).then(ret => {
      commit(types.UPDATE_GIFTORDER_LIST, ret.data.data);
      return ret;
    });
  },
  verifyGiftS({ commit }, param) {
    return Api.verifyGift(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.INIT_CURRENT_GIFTORDER](state, payload) {
    state.currentGiftOrder = {};
  },
  [types.UPDATE_CURRENT_GIFTORDER](state, payload) {
    console.log(payload);
    state.currentGiftOrder = payload;
  },
  [types.UPDATE_GIFTORDER_LIST](state, payload) {
    state.giftOrderList = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
